package com.jinmdz.fmis.dao.dao;

import com.jinmdz.fmis.dao.dao.provider.ColdStorageEquipmentProvider;
import com.jinmdz.fmis.dao.model.coldstorage.ColdStorageEquipmentItem;
import com.jinmdz.fmis.dao.model.coldstorage.ColdStorageEquipmentViewItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

/**
 * 冷藏设备Dao
 *
 * @author LiCongLu
 * @date 2020-02-15 10:08
 */
public interface ColdStorageEquipmentDao {

    /**
     * 按照主键获取冷藏设备信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-02-15 10:04
     */
    @Select(" select id,equipment_type_code,equipment_code,equipment_describe,equipment_state,column_no,row_no,disable_state,sort,remark,version" +
            " from cold_storage_equipment where id = #{id} and deleted=0 ")
    ColdStorageEquipmentItem getColdStorageEquipmentById(@Param("id") Integer id);

    /**
     * 按照类型字典编码值查询冷藏设备信息
     *
     * @param dictCode 冷藏类型字典编码
     * @param dataCode 冷藏类型编码
     * @return
     * @author LiCongLu
     * @date 2020-02-15 17:57
     */
    @SelectProvider(type = ColdStorageEquipmentProvider.class, method = "listColdStorageEquipmentByDictCode")
    ArrayList<ColdStorageEquipmentItem> listColdStorageEquipmentByDictCode(@Param("dictCode") String dictCode, @Param("dataCode") Integer dataCode);

    /**
     * 按照主键获取冷藏设备信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-02-17 10:42
     */
    @SelectProvider(type = ColdStorageEquipmentProvider.class, method = "getColdStorageEquipmentViewById")
    ColdStorageEquipmentViewItem getColdStorageEquipmentViewById(@Param("id") Integer id);

    /**
     * 按照类型字典编码值查询冷藏设备信息
     *
     * @param dictCode 类型字典编码
     * @param dataCode 类型编码
     * @param outState 出藏状态
     * @return
     * @author LiCongLu
     * @date 2020-02-17 10:53
     */
    @SelectProvider(type = ColdStorageEquipmentProvider.class, method = "listColdStorageEquipmentViewByDictCode")
    ArrayList<ColdStorageEquipmentViewItem> listColdStorageEquipmentViewByDictCode(@Param("dictCode") String dictCode, @Param("dataCode") Integer dataCode, @Param("outState") Integer outState);

    /**
     * 更新状态值
     *
     * @param state          状态值
     * @param modifiedUserId 修改帐号
     * @param id             主键
     * @param version        版本号
     * @return
     * @author LiCongLu
     * @date 2020-02-17 13:27
     */
    @Update(" update cold_storage_equipment set equipment_state = #{state},modified_user_id = #{modifiedUserId},version = unix_timestamp(now()) where id = #{id} and version = #{version} and unmodified = 0 and deleted = 0 ")
    void updateStateById(@Param("state") Integer state, @Param("id") Integer id, @Param("modifiedUserId") Integer modifiedUserId, @Param("version") Long version);
}